[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
calloc() Allocate and Zero Memory
#include <stdlib.h> Required for declarations only
#include <alloc.h>
void *calloc(n,size);
size_t n; Number of elements to allocate
size_t size; Number of bytes in each element
calloc() allocates storage for 'n' elements of 'size' bytes each.
All elements are initialized to 0. The storage space is guaranteed
to be correctly aligned for any data type.
Returns: A pointer to the allocated space, or NULL (defined in
<stdio.h>) if the space cannot be allocated. If
'size' == 0, NULL is returned.
Notes: Memory allocated with calloc() should only be freed
with free().
-------------------------------- Example ---------------------------------
The following statements allocate space for 50 long integers and then
free the allocated space.
#include <alloc.h>
#include <stdio.h> /* for printf and NULL */
long *memptr;
main()
{
if ((memptr = (long *) calloc(50, sizeof(long))) == NULL)
printf("not enough room to allocate memory\n");
else {
.
.
free(memptr);
}
}
See Also:
malloc()
realloc()
free()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson